import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [{
        path: '/bottom',
        name: 'bottom',
        component: () =>
            import ('../views/BottomView.vue'),
        children: [{
                path: '/shouye',
                name: 'shouye',
                meta: { title: "首页" },
                component: () =>
                    import ('../views/erji/ShouYe.vue')
            },
            {
                path: '/fenlei',
                name: 'fenlei',
                meta: { title: "分类" },
                component: () =>
                    import ('../views/erji/FenLei.vue')
            },

            {
                path: '/qianggou',
                name: 'qianggou',
                meta: { title: '爆爆团' },
                component: () =>
                    import ('../views/erji/QiangGou.vue')
            },
            {
                path: '/dingdan',
                name: 'dingdan',
                meta: { title: '订单' },
                component: () =>
                    import ('../views/erji/DingDan.vue')
            },
            {
                path: '/wode',
                name: 'wode',
                meta: { title: '我的' },
                component: () =>
                    import ('../views/erji/WoDe.vue')
            },

            {
                // 路由地址中带有 :xxx 的路由地址 都属于动态路由
                // path: '/detail/:name', // :name 是个占位符, 实际在跳路由的时候,会动态拼接参数 例如: '/detail/'+100
                path: '/data/:name', //这是params方式需要添加
                // path: '/data', // 这是query方式不添加
                name: 'data',
                component: () =>
                    import ('../views/erji/DataView.vue')
            },
            // 重定向
            {
                path: "/",
                redirect: "/shouye"
            },
            // 404页面
            {
                path: '*',
                component: () =>
                    import ('../views/NotFound.vue')
            }
        ]
    },
    {
        path: '/login',
        name: 'login',
        meta: { title: '登录' },
        component: () =>
            import ('../views/LoginView.vue')
    },
    {
        path: '/shopview',
        name: 'shopview',
        meta: { title: "详情页" },
        component: () =>
            import ('../views/ShopView.vue')
    },
    {
        path: '/register',
        name: 'register',
        meta: { title: '注册' },
        component: () =>
            import ('../views/RegisterView.vue')
    },
    // 重定向
    {
        path: "/",
        redirect: "/bottom"
    },
    // 404页面
    {
        path: '*',
        component: () =>
            import ('../views/NotFound.vue')
    }
]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})
router.beforeEach((to, from, next) => {
    document.title = to.meta.title;
    // var token = localStorage.getItem('token');
    // if (to.path == '/dingdan' || to.path == '/wode') {
    //     if (token) {
    //         next()
    //     } else {
    //         next('/login')
    //     }
    // } else {
    //     next()
    // }
    next()
})

export default router